using System;
using System.Collections.Generic;
using System.Text;

namespace Tomahawk.Runtime.Logic
{
    /// <summary>
    /// This is a component that can be placed undes scene management (SceneManager)
    /// </summary>
    public class XSceneComponent : XComponent
    {

        private Scene.SceneNode sceneNode;

        /// <summary>
        /// Scene Node of the component
        /// </summary>
        public Scene.SceneNode SceneNode
        {
            get { return sceneNode; }
        }

        /// <summary>
        /// Initialization
        /// </summary>
        protected override void OnInitialize()
        {
            base.OnInitialize();

            //this component requires per frame update
            this.UpdateRequired = true;

            //create the scene node
            this.sceneNode = Engine.Instance.SceneManager.RootNode.CreateChildSceneNode();
        }

        /// <summary>
        /// Invokes the preRender chain
        /// </summary>
        internal void PreRender()
        {
            this.OnPreRender();
        }

        /// <summary>
        /// Default Pre-Render implementation:
        ///  - copies translation, scale, and rotation from the parent logic object
        /// </summary>
        protected virtual void OnPreRender()
        {
        }

        /// <summary>
        /// Destruction of the rendering component
        /// </summary>
        public override void OnBeforeDestroy()
        {
            base.OnBeforeDestroy();

            //destroy the sceneNode
            this.sceneNode.Destroy();
        }

        /// <summary>
        /// Allow reparenting between scene components
        /// </summary>
        public void SetParent(XSceneComponent xSceneComponent)
        {
            this.sceneNode.SetParent(xSceneComponent.sceneNode);
        }
    }

}
